home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
C++ Files Library
/
Direct Blitting in C++
/
Blitting.sit
/
Blitting ƒ
/
CCopier.cp
< prev
next >
Wrap
Text File
|
1995-04-21
|
4KB
|
144 lines
// CCopier.cp, the CCopier class methods, for image copying
//
// Copyright ⌐ 1995, Macneil Shonle. All rights reserved.
#ifndef __CCOPIER__
#include <CCopier.h>
#endif
#ifndef __CDIRECTBLIT__
#include <CDirectBlit.h>
#endif
#ifndef __STGWORLDSETTER__
#include <StGWorldSetter.h>
#endif
#ifndef __STMMUMODESWAPPER__
#include <StMMUModeSwapper.h>
#endif
#ifndef __PIXELTYPES__
#include <PixelTypes.h>
#endif
CCopier::CCopier( CDirectBlit *inSource, CDirectBlit *inDest,
CopyMethod inCopy, SwapMethod inSwap )
{ mSource = inSource;
mDest = inDest;
mCopyMethod = inCopy;
mSwapMethod = inSwap;
}
void CCopier::SetSource( CDirectBlit *inSource )
{ mSource = inSource;
}
void CCopier::SetDest( CDirectBlit *inDest )
{ mDest = inDest;
}
void CCopier::SetCopyMethod( CopyMethod inCopy )
{ mCopyMethod = inCopy;
}
void CCopier::SetSwapMethod( SwapMethod inSwap )
{ mSwapMethod = inSwap;
}
void CCopier::operator()( Rect *sourceRect, Rect *destRect )
{ switch( mCopyMethod )
{ case kDirect8To8:
Direct8To8Copy( sourceRect, destRect );
break;
case kQuickDraw:
QuickDrawCopy( sourceRect, destRect );
break;
}
}
void CCopier::Direct8To8Copy( Rect *sourceRect, Rect *destRect )
{ // Init the source and dest pointers
register FourPixelsPtr source =
FourPixelsPtr(mSource->GetAddressOfPixel( sourceRect->left, sourceRect->top ));
register FourPixelsPtr dest =
FourPixelsPtr(mDest->GetAddressOfPixel( destRect->left, destRect->top ));
// Get in the correct addressing mode
int mode = (mSwapMethod == kAutoSwap) ? (mDest->Use32Bit() | mSource->Use32Bit()) : false;
StMMUModeSwapper swapTo( mode );
RowWidth copyWidth = destRect->right - destRect->left;
ColumnHeight numberOfRows = destRect->bottom - destRect->top;
register RowWidth sourceNextRow = mSource->GetRowBytes() - copyWidth;
register RowWidth destNextRow = mDest->GetRowBytes() - copyWidth;
do
{ register int width = copyWidth;
// long-word align the address
int bytesBeforeAlignment = 4 - ( long(source) & 0x3L );
if( bytesBeforeAlignment < 4 )
{ do
{ if( width )
{ *PixelPtr(dest) = *PixelPtr(source);
dest = FourPixelsPtr(PixelPtr(dest) + 1);
source = FourPixelsPtr(PixelPtr(source) + 1);
--width;
}
else
return;
} while( --bytesBeforeAlignment );
}
if( width < 4 )
goto FinishOffBytes;
// use Duff's device for the pixel chunks
int chunksToMove = width >> 2;
int timesCopy = (chunksToMove + 7) >> 3;
switch( chunksToMove & 0x7 )
{ case 0: do
{ *dest++ = *source++;
case 7: *dest++ = *source++;
case 6: *dest++ = *source++;
case 5: *dest++ = *source++;
case 4: *dest++ = *source++;
case 3: *dest++ = *source++;
case 2: *dest++ = *source++;
case 1: *dest++ = *source++;
} while( --timesCopy > 0 );
}
FinishOffBytes:
// move 1, 2 or 3 bytes
if( width & 1 )
{ *PixelPtr(dest) = *PixelPtr(source);
dest = FourPixelsPtr(PixelPtr(dest) + 1);
source = FourPixelsPtr(PixelPtr(source) + 1);
}
if( width & 2 )
{ *TwoPixelsPtr(dest) = *TwoPixelsPtr(source);
dest = FourPixelsPtr(TwoPixelsPtr(dest) + 1);
source = FourPixelsPtr(TwoPixelsPtr(source) + 1);
}
// jump down to the next row
source = FourPixelsPtr(PixelPtr(source) + sourceNextRow);
dest = FourPixelsPtr(PixelPtr(dest) + destNextRow);
} while( --numberOfRows );
}
void CCopier::QuickDrawCopy( Rect *sourceRect, Rect *destRect )
{ StGWorldSetter setTo( mDest->GetMacPort(), mDest->GetMacDevice() );
::CopyBits( mSource->GetBitMap(), mDest->GetBitMap(),
sourceRect, destRect, srcCopy, nil );
}